 # Нужна библиотека sympy
 # pip install sympy
from sympy import isprime
def it_marafone(number):
    str_number = str(number)
    max_prime = 0
    length = len(str_number)
    
    for i in range(length):
        for j in range(i + 1, length + 1):
            substring = str_number[i:j]
            candidate = int(substring)
            if isprime(candidate):
                max_prime = max(max_prime, candidate)
                
    return max_prime

prost_chislo = input().strip()

if not prost_chislo.isdigit() or len(prost_chislo) != 4:
    print(0)
else:
    print(it_marafone(int(prost_chislo)))
